//
//  ByCellGoodsIndexRecommend.m
//  mijifen_ios
//
//  Created by mc on 2017/11/6.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByCellGoodsIndexRecommend.h"

@implementation ByCellGoodsIndexRecommend
{
    UIView      *_bgView;
    UIView      *_leftBgView;
    UIView      *_rightBgView;
    UIView      *_priceBgView;
    UIView      *_blackView;
    
    UILabel     *_termLabel;        // 期限
    UILabel     *_priceLabel;       // 价格
    
}

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByCellGoodsIndexRecommend";
    ByCellGoodsIndexRecommend *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.backgroundColor = [UIColor clearColor];
        [self createViews];
    }
    return self;
}

- (void)createViews{
    _bgView = [[UIView alloc] init];
    [self addSubview:_bgView];
    
    // 价格
    _leftBgView = [[UIView alloc] init];
    [_bgView addSubview:_leftBgView];
    
    _priceBgView = [[UIView alloc] init];
    [_leftBgView addSubview:_priceBgView];
    _priceBgView.layer.borderWidth = 1;
    _priceBgView.layer.borderColor = [UIColor blackColor].CGColor;
    
    _blackView = [[UIView alloc] init];
    [_leftBgView addSubview:_blackView];
    _blackView.backgroundColor = [UIColor blackColor];
    
    _priceLabel = [[UILabel alloc] init];
    [_priceBgView addSubview:_priceLabel];
    _priceLabel.font = FONT(30);
    _priceLabel.textAlignment = NSTextAlignmentCenter;
    
    // 期限
    _rightBgView = [[UIView alloc] init];
    [_bgView addSubview:_rightBgView];
    
    _termLabel = [[UILabel alloc] init];
    [_rightBgView addSubview:_termLabel];
    _termLabel.textAlignment = NSTextAlignmentCenter;
    _termLabel.font = FONT(16);
    _termLabel.textColor = [UIColor whiteColor];
    
}

- (void)setModel:(ByModelGoodsRecommend *)model{
    _model = model;
    
    // 背景视图
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(10));
        make.top.equalTo(@(0));
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 20, 100));
    }];
    
    // 右侧期限视图
    CGFloat width = [@"12个月" getSizeOfString:16].width + 20;
    [_rightBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(0));
        make.top.equalTo(@(0));
        make.size.mas_equalTo(CGSizeMake(width, 100));
    }];
    _rightBgView.backgroundColor = [UIColor colorWithR:224 g:124 b:42];
    
    [_termLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(0));
        make.right.equalTo(@(0));
        make.centerY.equalTo(_rightBgView.mas_centerY);
        make.height.equalTo(@(30));
    }];
    _termLabel.text = [NSString stringWithFormat:@"%@个月",_model.term];
    
    // 左侧价格背景视图
    [_leftBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(0));
        make.top.equalTo(@(0));
        make.right.equalTo(_rightBgView.mas_left);
        make.height.equalTo(@(100));
    }];
    
    [_blackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(0));
        make.centerY.equalTo(_leftBgView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(15, 30));
    }];
    
    [_priceBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(20));
        make.right.equalTo(@(-20));
        make.top.equalTo(@(10));
        make.bottom.equalTo(@(-10));
    }];
    
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_priceBgView.mas_centerY);
        make.left.equalTo(@(10));
        make.right.equalTo(@(-10));
        make.height.equalTo(@(40));
    }];
    _priceLabel.font = FONT(30);
    _priceLabel.text = [NSString stringWithFormat:@"¥%@",_model.price];
    
    _leftBgView.backgroundColor = [UIColor whiteColor];
    _leftBgView.layer.borderColor = [UIColor colorWithR:224 g:124 b:42].CGColor;
    _leftBgView.layer.borderWidth = 1;
    _priceBgView.backgroundColor = [UIColor colorWithR:211 g:212 b:213];
}

- (void)setSelected:(BOOL)selected{
    _leftBgView.backgroundColor = BY_TEXT_COLOR;
    _priceBgView.backgroundColor = BY_TEXT_COLOR;
    
}


@end
